<template>
  <div class="uIndex">
    <u-header :title="tit"></u-header>
    <div class="box">
      <div class="search">
        <van-icon size="37" color="white" name="location-o" />
        <img class="logo" src="../assets/images/white.png" alt="" />
        <van-search
          @keydown.enter="goSearch()"
          background="transparent"
          class="search_box"
          v-model="keyword"
          placeholder="请输入关键词"
        />
        <van-icon size="37" name="shop-o" />
      </div>
      <!-- <ul class="navigation">
        <li class="chocked">
          <span>推荐</span>
          <div class="line"></div>
        </li>
        <li>女装</li>
        <li>鞋包</li>
        <li>居家</li>
        <li>母婴</li>
        <li>美妆</li>
        <li>分类</li>
      </ul> -->
    </div>
    <van-tabs background='skyblue' class="navigation111" v-model="active">
      <van-tab v-for="item in arr3" :key="item.id" :title="item.catename"></van-tab>
    </van-tabs>
    <!-- 轮播图组件 -->
    <u-banner> </u-banner>
    <ul class="u_select">
      <li>
        <img src="../assets/images/seckill.png" alt="" />
        <span>限时秒杀</span>
      </li>
      <li>
        <img src="../assets/images/top.png" alt="" />
        <span>畅销商品</span>
      </li>
      <li>
        <img src="../assets/images/brand.png" alt="" />
        <span>品质大牌</span>
      </li>
      <li>
        <img src="../assets/images/selfsupport.png" alt="" />
        <span>小U自营</span>
      </li>
      <li>
        <img src="../assets/images/integral.png" alt="" />
        <span>积分商城</span>
      </li>
    </ul>
    <!-- 倒计时 -->
    <div class="xianshi">
      <div class="left">
        <div class="one">限时抢购</div>
        <div class="two">
          <span>111111</span>
          <i>:</i>
          <span>2222</span>
          <i>:</i>
          <span>33333</span>
          <i>:</i>
          <span>444</span>
        </div>
      </div>
      <div class="right">
        <div class="right-top">
          <div class="one">品牌上新</div>
          <div class="two">九点整，抢大牌</div>
          <div class="three">疯抢红包 ></div>
        </div>
        <div class="right-bottom">
          <div class="one">日用好物</div>
          <div class="two">愿君多采撷</div>
          <div class="three"></div>
        </div>
      </div>
    </div>
    <!-- 下部分 -->
    <div class="sort">
      <div class="shiyi">
        <div class="title">
          <span>双十一尖货预购</span>
          <span>畅购全球</span>
        </div>
        <div class="content">
          <ul>
            <li v-for="item in arr2" :key="item.id">
              <img :src="item.img" alt="" />
            </li>
          </ul>
        </div>
      </div>
      <div class="hot-tab">
        <div class="hot-title">
          <ul>
            <li
              v-for="(item, index) in ['热门推荐', '上新', '推荐']"
              :key="index"
            >
              {{ item }}
            </li>
          </ul>
        </div>
        <div class="hot-main">
          <ul>
            <li @click="goDetail(item.id)" v-for="item in arr1" :key="item.id">
              <div class="left">
                <img :src="item.img" alt="" />
              </div>
              <div class="right">
                <p>{{ item.goodsname }}</p>
                <p>现价格： {{ item.price }}</p>
                <p>原价格： ￥{{ item.market_price }}</p>
                <p><button>立即抢购</button></p>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <u-nav></u-nav>
  </div>
</template>
<script>
import uNav from "../components/public/uNav.vue";
import uBanner from "../components/index/uBanner.vue";
import uHeader from "../components/public/uHeader.vue";
import http from "../utils/http";
export default {
  components: {
    uHeader,
    uBanner,
    uNav,
  },
  data() {
    return {
      tit: "小U商城",
      active: 2,
      keyword: "",
      arr1: [],
      arr2: [],
      arr3: []
    };
  },
  mounted() {
    //获取相关图片
    http.get("/api/goodslist?size=3&page=1").then((res) => {
      res.list.forEach((item) => {
        item.img = this.$pregImg + item.img;
        this.arr1.push(item);
      });
    });
    //
    http.get("/api/goodslist?size=4&page=3").then((res) => {
      res.list.forEach((item) => {
        item.img = this.$pregImg + item.img;
        this.arr2.push(item);
      });
    });
    //获取分类信息
    this.goClass()
  },
  methods: {
    //搜索事件
    goSearch() {
      this.$router.push({ path: "/search", query: { keyword: this.keyword } });
    },
    goDetail(id) {
      this.$router.push({ path: "detail", query: { id } });
    },
    goClass(){
      http.get('/api/getcate').then(res=>{
        this.arr3=res.list
      })
    },
  },
};
</script>
<style lang="less" scoped>
.box {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  max-width: 7.5rem;
  height: 1.6rem;
  margin: 0 auto;
  background-image: linear-gradient(180deg, #ff6040 0%, #ff8a80 100%);
  box-shadow: 0 0.02rem 6px 0 rgba(255, 149, 128, 0.5);
}
.search {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  max-width: 7.5rem;
  height: 0.64rem;
}
.logo {
  width: 1.82rem;
  height: 0.48rem;
}
.search /deep/ .search_box {
  width: 3.4rem;
  height: 0.64rem;
}
.navigation111 {
  width: 100%;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  font-size: 0.3rem;
  color: #fff3f2;
}
.fenlei {
  display: flex;
}
.icon-fenlei {
  font-size: 0.4rem;
}
.u_select {
  background: #fff;
  font-size: 0.2rem;
  width: 100%;
  height: 1.5rem;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.u_select li {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
/*限时秒杀*/

.xianshi {
  height: auto;
  margin-top: 0.23rem;
  width: 100%;
  overflow: hidden;
  height: 3.3rem;
  padding: 0 0.23rem;

  .left {
    float: left;
    width: 3.28rem;
    height: 3.28rem;
    background-image: url("../assets/images/goods/02.png");
    background-size: 3.28rem;
    padding: 5px 0 0 10px;
    // font-size: 13px;
    .one {
      font-size: 18px;
      font-weight: 900;
      color: #90a950;
    }
    .two {
      margin-top: 5px;
      font-size: 13px;
      font-weight: 900;
      color: #e6eed6;
      span {
        display: inline-block;
        background-color: #617c37;
        padding: 0 3px;
      }
      i {
        font-style: normal;
        color: #617c37;
        margin: 0 3px;
      }
    }
  }
  .right {
    float: right;
    display: flex;
    flex-direction: column;
    width: 3.28rem;
    height: 3.28rem;
    justify-content: space-between;
    .right-top {
      width: 100%;
      height: 48%;
      background-color: #af3;

      padding: 5px 0 0 10px;
      background-image: url("../assets/images/goods/right02.png");
      .one {
        font-size: 17px;
        font-weight: 900;
        color: #f56049;
      }
      .two {
        margin-top: 2px;
        font-size: 15px;
        color: #f56049;
      }
      .three {
        margin-top: 2px;
        padding-left: 4px;
        width: 90px;
        height: 35px;
        line-height: 35px;
        background: linear-gradient(#ff6145, #ff9474);
        font-size: 16px;
        color: #fff;
        border-top-right-radius: 15px;
        border-bottom-right-radius: 15px;
      }
    }
    .right-bottom {
      width: 100%;
      height: 48%;
      padding: 5px 0 0 10px;
      background-image: url("../assets/images/goods/right01.png");
      .one {
        font-size: 17px;
        font-weight: 900;
        color: #ae44f6;
      }
      .two {
        margin-top: 20px;
        font-size: 14px;
        font-weight: 900;
        color: #ae55f1;
      }
      .three {
        margin-top: 10px;
        width: 70px;
        height: 5px;
        background-color: #b041fd;
        border-top-right-radius: 20px;
      }
    }
  }
}
.sort {
  width: 100%;
  height: auto;
  margin-top: 0.2rem;
  background-color: #fff;
  .shiyi {
    width: 100%;
    overflow: hidden;
    .title {
      width: 100%;
      height: 0.8rem;
      font-size: 0.32rem;
      display: flex;
      line-height: 0.8rem;
      color: #9e9e9e;
      margin-top: 0.13rem;
      span {
        flex: 1;
        text-align: center;

        font-weight: 900;
      }
    }
    .changes {
      color: #e26d55;
      font-size: 0.34rem;
    }
    .content {
      width: 100%;
      margin-top: 0.15rem;
      ul {
        display: flex;
        justify-content: center;
        li {
          padding: 0 0.05rem;
          img {
            width: 1.55rem;
            height: 1.55rem;
            border-radius: 0.2rem;
          }
        }
      }
    }
  }
  .hot-tab {
    width: 100%;
    height: auto;
    background-color: #fff;
    margin-top: 0.6rem;
    .hot-title {
      width: 100%;
      height: 0.8rem;
      ul {
        overflow: hidden;
        display: flex;
        align-items: center;
        height: 100%;
        padding: 0 0.3rem;
        li {
          flex: 1;
          text-align: center;
          font-size: 0.32rem;
          color: rgb(254, 166, 19);
          align-items: center;
          justify-content: center;
          display: flex;
        }
        .active {
          height: 0.6rem;
          background-color: #fea613;
          color: #fff;
          border-radius: 0.15rem;
        }
      }
    }

    .hot-main {
      width: 100%;
      height: auto;
      padding: 0 0.3rem;
      padding-bottom: 0.2rem;
      ul {
        width: 100%;
        height: auto;
        overflow: hidden;
        li {
          width: 100%;
          height: 3.5rem;
          margin-top: 0.25rem;
          border-radius: 0.2rem;
          border: 1px solid #ccc;
          overflow: hidden;
          display: flex;
          align-items: center;
          box-shadow: 0.02rem 0.02rem 0.1rem -0.04rem rgb(0, 0, 0, 0.5);
          .left {
            margin-left: 0.47rem;
            img {
              width: 2.2rem;
              height: 2.2rem;
            }
          }
          .right {
            font-size: 0.28rem;
            margin-left: 0.4rem;
            p {
              line-height: 0.5rem;
            }
            p:first-child {
              // font-size: 0.28rem;
              font-weight: 900;
            }
            p:nth-child(2) {
              color: red;
              font-size: 0.29rem;
            }
            p:nth-child(3) {
              text-decoration: line-through;
              color: rgb(205, 205, 205);
              font-size: 0.27rem;
            }
            p:last-child {
              margin-top: 0.1rem;
              button {
                width: 2rem;
                height: 0.54rem;
                background-color: #fea613;
                color: #fff;
                font-size: 0.27rem;
                border-radius: 0.08rem;
              }
            }
          }
        }
      }
    }
  }
}
</style>
